home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 128 29 / q29.d81 / t.st demo < prev    next >
Text File  |  2022-08-28  |  17KB  |  353 lines

  1.  
  2.  
  3.                             S T E P T R A C E R
  4.  
  5.                        Program and Text by e. g. bell
  6.  
  7.  
  8. FENDER'S PREMUMBLE: StepTracer is a programmer's utility and is not
  9. designed to be something you can access from LOADSTAR 128's menu.  However,
  10. ed has provided a revised version of CONTROL80's demo, which shows you that
  11. StepTracer works with CONTROL80 programs -- at least on a C-128D.  I
  12. couldn't get it to work right on a flat C-128, so I don't recommend looking
  13. at the demo on a flat C-128 unless you like a blank screen half way through
  14. the demo.  My theory is that CONTROL80's VLOAD command is a little too
  15. weird for StepTracer.  It's also hardcoded for drive 8.  I don't consider
  16. VSAVE and VLOAD to be among CONTROL80's more useful commands so you should
  17. still be able to use StepTracer with your CONTROL80 programs.  Even on a
  18. C-128D there is a spot at the end of the demo where it asks you to press a
  19. key while the screen scrolls horizontally.  Press RESTORE instead and you
  20. get back to the demo's title screen where you can return to LOADSTAR 128.
  21.  
  22.  
  23. *** StepTracer
  24.  
  25.     When debugging a BASIC program, it is often necessary to follow the
  26. flow of logic.  When you get unexpected results, is the program doing what
  27. you want it to do or is it just doing what you told it to do?  There are
  28. several utilities of varying degrees of usefulness in determining this.
  29.  
  30. *** Dump
  31.  
  32.     There are 'dump' utilities which dump the names and current values of
  33. all variables.  Using such a utility usually requires frequent STOPs to
  34. check these values at various points in the program operation.
  35.  
  36.     This can be useful in determining why or where something is happening
  37. in a program, but a computer executes a program at an extremely high rate
  38. of speed.  Couple that with the many twists and turns the program can take
  39. while getting from here to there and it can be a long, time-consuming
  40. process to isolate and fix some problems using only a dump utility.
  41.  
  42. *** Follow Me
  43.  
  44.     More useful are the 'trace' utilities.  Most of these trace program
  45. flow by printing the line number, to the screen inside brackets, of the
  46. BASIC statement currently being executed.  For example, consider the
  47. following code:
  48.  
  49.       10 print chr$(147):na$="":cnt=0:input "Enter Name  ";na$
  50.  
  51. If you used the BASIC 7.0 TRON command, it would produce the following
  52. screen display:
  53.  
  54.       [10][10][10][10]Enter Name  ?
  55.  
  56. If you have never tried this with your Commodore 128 BASIC programs, type
  57. TRON then run any BASIC program.  [TROFF toggles this function off.]  
  58.  
  59.     There have been many such utilities published for the C64 over the
  60. years also.  Most, if not all of these, function exactly the same.  As
  61. helpful as this type of utility is, as you may have noticed from the
  62. example, there are some serious limitations.
  63.  
  64. *** Drawbacks
  65.  
  66.     First, using this type of trace, screen display is hopelessly disrupted
  67. as rows and rows of line numbers are dutifully displayed onscreen starting
  68. wherever the cursor happened to be resting at the time.  There is much
  69. information presented, but it is confusing if you can use it at all.  This
  70. is particularly true in the case of deeply nested loops or GOSUB/GOTO
  71. procedures.  The information can be simply overwhelming.
  72.  
  73.     Second, often you know where something is happening, but cannot locate
  74. where the offending code is being called.  This can be particularly
  75. troublesome to find if the code is called from several places.  Which call
  76. is causing the problem?  StepTracer will help you isolate such calls
  77. quickly.  This capability of StepTracer will help you find and correct the
  78. problem areas instead of wasting a lot of time looking at the wrong place
  79. in your code.
  80.  
  81.     Third, the trace, like the program being traced, is operating at
  82. extreme speeds.  It is virtually impossible to visually follow the
  83. execution unless frequently stopped by user input or STOP statements.  This
  84. can be irritating and confusing.  If sections of the code being traced
  85. clear the screen, it can be quite impossible.  If you STOP the program, you
  86. must start it again with a GOTO, CONT, or RUN.  If you merely request user
  87. input, the screen display problem mentioned above presents itself,
  88. particularly if you are trying to find out why something is being displayed
  89. WHERE it is being displayed.
  90.  
  91.     Finally, you learn little from only a line number unless you are
  92. working with a program listing in front of you, especially when a problem
  93. involves several lines or routines.  Since you are usually the person who
  94. wrote the program, it is your logic.  If the logic in the listing was
  95. working as expected, you wouldn't need to trace the flow.  In addition, if
  96. the program flow jumps around a lot, with GOSUBs for example, it can become
  97. difficult to follow the logical flow from a listing alone.  So a listing by
  98. itself is often of limited help in battling some bugs.
  99.  
  100. *** A Solution
  101.  
  102.     There is a solution.  StepTracer is a short single-step trace routine
  103. for the Commodore 128 in 80 column mode.  It will not work in 40 column
  104. mode.   StepTracer will lead you along the precise route your program is
  105. taking.  But it does more!
  106.  
  107.     More than just the line numbers, the complete segment of BASIC code TO
  108. BE EXECUTED is displayed for you prior to its execution.  You know what
  109. will take place and in which line it was commanded to do so just BEFORE it
  110. actually happens.
  111.  
  112.     If that is not enough, there is virtually no disruption of screen
  113. display.  Using some interesting capabilities of the VDC chip in your
  114. Commodore 128, StepTracer gives you some extra lines at the bottom of your
  115. screen IN ADDITION TO the normal 25 lines.  But it does still more.
  116.  
  117. *** Single Step
  118.  
  119.     Even displaying a segment of code would be of minimal value if it
  120. happened at extreme speed, so StepTracer is an adjustable speed trace
  121. utility AND a single-stepper.  You may slog through your code at various
  122. speeds OR step through your program one segment at a time if you like.  
  123.  
  124.     In single-step mode, after the program segment is displayed, you must
  125. press a SHIFT Key to continue.  (In single-step mode, a '*' is displayed
  126. after the line number and before the program text to flag that user input
  127. is expected before the program can continue)  When you do, the segment of
  128. code you are looking at is executed and the next segment is displayed.  If,
  129. for example, the current segment says GOTO 50 the next thing you will see
  130. in the trace window is the first code segment of line 50.  This feature
  131. could also be helpful to novice computer programmers wondering what
  132. different segments of someone else's code do.
  133.  
  134.     In single-step mode, if you want to stop the program for editing, you
  135. must press the STOP key and then press the SHIFT key to resume execution.
  136. The program will then stop normally.
  137.  
  138.     Note that I refer to code 'segments' above rather than just 'lines'.
  139. This is because BASIC evaluates lines of code in this manner when there are
  140. multiple commands on a single line.  In cases like this, StepTracer lists
  141. each such command individually, just as BASIC will execute it.  The line
  142. number remains onscreen though, so regardless of which segment is being
  143. displayed, the appropriate line number is always evident.
  144.  
  145. *** Tron
  146.  
  147.     Using StepTracer is very simple and will interfere with no BASIC
  148. programs.  First, you must install it using the BLOAD command:
  149.  
  150.     bload "StepTracer"
  151.  
  152. Next, you simply activate it: 
  153.  
  154.     sys 2816,a,b
  155.  
  156.     a =    0-Trace Disabled    1-Trace Enabled
  157.  
  158.     b =    0-6 Speed of trace display   0-fastest  6-slowest
  159. or  b =    128 Requires pressing SHIFT after each segment displayed
  160.  
  161. So, to turn the trace on with a speed factor of 3, the command would be:
  162.  
  163.     sys 2816,1,3
  164.  
  165. To turn the trace on with a speed factor of 0, the fastest possible, the
  166. command would be:
  167.  
  168.     sys 2816,1,0
  169.  
  170. To turn the trace on and specify that you must press the SHIFT key after
  171. each segment is displayed, the command would be:
  172.  
  173.     sys 2816,1,128
  174.  
  175. If you just want to toggle trace mode on with the current speed setting
  176. unchanged, you may use the BASIC 7.0 'TRON' command in your BASIC program.
  177. StepTracer recognizes this command as its own and resumes the trace.  For
  178. this reason, the normal function